/*
 * @lc app=leetcode.cn id=1700 lang=javascript
 *
 * [1700] 无法吃午餐的学生数量
 */

// @lc code=start
Array.prototype.top = function () {
  return this[this.length - 1];
}
/**
 * @param {number[]} students
 * @param {number[]} sandwiches
 * @return {number}
 */
var countStudents = function (students, sandwiches) {
  sandwiches.reverse();
  let cur = students.length;
  let num = 0;
  while (num !== cur) {
    const student = students.shift();
    if (student === sandwiches.top()) {
      cur--;
      sandwiches.pop();
      num = 0;
    } else {
      students.push(student);
      num++;
    }
  }
  return cur;
};
// @lc code=end
